home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x03.exe / ADDTRUST.C next >
C/C++ Source or Header  |  1993-04-09  |  7KB  |  170 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      addtrust.c                                            ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface for the SetTrustee API,        ║
  6. //   ║              obviously it requires the NetWare Shell.              ║
  7. //   ║                                                                    ║
  8. //   ║              The user object name entered must be of type USER     ║
  9. //   ║              for the purposes of this example.  Supporting other   ║
  10. //   ║              object types is quite straightforward, and is left    ║
  11. //   ║              as an exercise to the reader.                         ║
  12. //   ║                                                                    ║
  13. //   ║              Whatever pathname is entered must be for the          ║
  14. //   ║              currently logged drive, as the path is not checked    ║
  15. //   ║              in this example.  Wildcard expressions are not        ║
  16. //   ║              supported.                                            ║
  17. //   ║                                                                    ║
  18. //   ║ environment: NetWare 3.x v3.11                                     ║
  19. //   ║              Borland C++ 3.1                                       ║
  20. //   ║                                                                    ║
  21. //   ║  This software is provided as is and carries no warranty           ║
  22. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  23. //   ║  warranties of merchantability, title and fitness for a particular ║
  24. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  25. //   ║  your requirements or that the software is without defect or error ║
  26. //   ║  or that operation of the software will be uninterrupted.  You are ║
  27. //   ║  using the software at your risk.  The software is not a product   ║
  28. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  29. //   ║                                                                    ║
  30. //   ╚════════════════════════════════════════════════════════════════════╝
  31. //   
  32. //                         ****** N O T I C E ******
  33. //
  34. //     This software is considered pre-release and may be used at your own
  35. //     risk and has been provided due to the many requests of our cust-
  36. //     omers.  Support for this module will be provided at the sole
  37. //     discretion of Novell, Inc.
  38. //
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <dos.h>
  43. #include <dir.h>
  44.  
  45. #include "nwsys.h"
  46.  
  47. struct TR_REQUEST {
  48.     WORD  sfLen;            // length of the structure
  49.     BYTE  sfCode;           // subfunction code
  50.     BYTE  dirHandle;        // directory handle
  51.     DWORD objectID;         // bindery object ID
  52.     WORD  trusteeRights;    // bitmap of trustee rights
  53.     BYTE  pathLength;       // directory path length
  54.     BYTE  path[255];        // directory path buffer
  55. } trusteeRequest;
  56.  
  57. struct BIND_REQUEST {
  58.     WORD  sfLen;            // length of the structure
  59.     BYTE  sfCode;           // subfunction code
  60.     WORD  objectType;       // bindery object type
  61.     BYTE  objectNameLength; // name length: 1 to 47
  62.     BYTE  objectName[48];   // bindery object name
  63. } binderyRequest;
  64.  
  65. struct BIND_REPLY {
  66.     WORD  replyLen;         // length of reply buffer
  67.     DWORD objectID;         // bindery object ID
  68.     WORD  objectType;       // bindery object type
  69.     BYTE  objectName[48];   // bindery object name
  70. } binderyReply;
  71.  
  72. WORD NWSystemCall2(BYTE func,             // function code
  73.                      void far * req,        // request buffer
  74.                    void far *rep)         // reply buffer
  75. {
  76.     union   REGS    regs;
  77.     struct  SREGS   sregs;
  78.  
  79.     segread(&sregs);
  80.  
  81.     memset(®s, 0, sizeof(regs));
  82.  
  83.     regs.h.ah = func;               // AH = function code
  84.     regs.x.si = FP_OFF(req);        // SI = request buffer offset
  85.     regs.x.di = FP_OFF(rep);        // DI = reply buffer offset
  86.  
  87.     sregs.ds = FP_SEG(req);         // DS = request buffer segment
  88.     sregs.es = FP_SEG(rep);         // ES = reply buffer segment
  89.  
  90.     intdosx(®s,®s,&sregs);    // do the Int 21
  91.  
  92.     return (WORD)regs.h.al;         // return code is in AL
  93. }
  94.  
  95. WORD GetBinderyObjectID(char *userName, WORD objectType, DWORD *objectID)
  96. {
  97.     int retCode;
  98.  
  99.     binderyRequest.sfLen = sizeof(binderyRequest);
  100.     binderyRequest.sfCode = 0x35;
  101.     binderyRequest.objectType = WordSwap(objectType);
  102.     binderyRequest.objectNameLength = strlen(userName);
  103.     strcpy(binderyRequest.objectName, userName);
  104.     binderyReply.replyLen = sizeof(binderyReply);
  105.     retCode = NWSystemCall2(0xe3, &binderyRequest, &binderyReply);
  106.     *objectID = binderyReply.objectID;
  107.     return(retCode);
  108. }
  109.  
  110. BYTE GetDirectoryHandle(int diskNumber)
  111. {
  112.     union REGS regs;
  113.  
  114.     memset(®s, 0, sizeof(regs));
  115.  
  116.     regs.h.ah = 0xe9;
  117.     regs.h.al = 0x00;
  118.     regs.x.dx = diskNumber;
  119.  
  120.     intdos(®s,®s);       // do the Int 21
  121.  
  122.     return(regs.h.al);         // return code is in AL
  123. }
  124.  
  125. int main()
  126. {
  127.     int retCode, diskNumber;
  128.     BYTE dirHandle;
  129.     DWORD userObjectID;
  130.     char userName[80], fileName[80];
  131.  
  132.     printf("Username to add: ");
  133.     gets(userName);
  134.  
  135.     printf("Pathname and/or filename to add to: ");
  136.     gets(fileName);
  137.  
  138.     retCode = GetBinderyObjectID(userName, 0x0001, &userObjectID);
  139.     if (retCode != 0) {
  140.         printf("GetBinderyObjectID call failed.  Return code = %d.\n",
  141.             retCode);
  142.         return(1);
  143.     }
  144.  
  145.     diskNumber = getdisk();
  146.  
  147.     dirHandle = GetDirectoryHandle(diskNumber);
  148.  
  149.     trusteeRequest.sfLen = sizeof(trusteeRequest);
  150.     trusteeRequest.sfCode = 0x27;
  151.     trusteeRequest.dirHandle = dirHandle;
  152.     trusteeRequest.objectID = userObjectID;
  153.  
  154.     /* Add Read and Write trustee rights */
  155.     trusteeRequest.trusteeRights = 0x0001 | 0x0002; 
  156.  
  157.     strcpy(trusteeRequest.path, fileName);
  158.     trusteeRequest.pathLength = strlen(trusteeRequest.path);;
  159.  
  160.     /* No reply packet necessary */
  161.     retCode = NWSystemCall(0x16, &trusteeRequest, sizeof(trusteeRequest),
  162.                                  NULL,            0);
  163.     if (retCode != 0) {
  164.         printf("SetTrustee call failed.  Return code = %d.\n",
  165.             retCode);
  166.         return(1);
  167.     }
  168.     return(0);
  169. }
  170.